package leetcode.L206;

import java.util.List;

class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
      val = x;
      next = null;
    }
}
public class Solution {
    public ListNode reverseList(ListNode head) {
        if (head == null) {
            return head;
        }
        //头插
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode tail = head;
        while (head.next != null) {
            tail = head.next;
            head.next = tail.next;
            tail.next=dummy.next;
            dummy.next = tail;
        }
        return dummy.next;
    }
}